/**
 * 添加菜单操作
 */
$('#cs_add_btn').click(function  () {
	var url = SCOPE.add_url;
	window.location.href=url;
});

/**
 * 表单操作
 */

$('#cs_sub_btn').click(function  () {
	var data =$('#cs_menu_form').serializeArray();
	postData = {};
	$(data).each(function  (i) {
		postData[this.name] =this.value;
	});
//	console.log(postData);
	var url = SCOPE.add_url;
	var jump_url = SCOPE.jump_url;
	$.post(url,postData,function(result){
		if (result.status==1) {
		 return	dialog.success(result.message,jump_url);
		}else if(result.status==0){
		 return	dialog.error(result.message);
		}
	},'json')
})

/**
 * 编辑操作
 */

$('.cs_menu_table #edit').click(function(){
	var id = $(this).attr('attr-id');
	var url=SCOPE.edit_url+'&id='+id;
	window.location.href=url;
})
/**
 * 删除操作
 */

$('.cs_menu_table #del').click(function(){
	var id = $(this).attr('attr-id');
	var url=SCOPE.del_url+'&id='+id;
	var message=$(this).attr('attr-message');
	
	var data={};
	data['id'] = id;
	data['status'] = -1;
	
	layer.open({
		type:0,
		title:'是否删除',
		btn:['yes','no'],
		icon:3,
		closeBtn:2,
		content:"是否确定"+message,
		scrollbar:true,
		yes:function  () {
			todel(url,data);
		}
	});

})

function todel (url,data) {
	$.post(url,data,function  (s) {
		if (s.status==1) {//跳转
			return dialog.success(s.message,'');
		} else{
			return dialog.error(s.message);
		}
	},'JSON');
}
/**
 * 排序操作
 */

$("#cs_listorder_btn").on('click',function  () {
	var data= $('#cs_listorder_form').serializeArray();
	postData={};
	$(data).each(function  (i) {
		postData[this.name] = this.value;
	})
	var url=SCOPE.listorder_url;
	$.post(url,postData,function  (result) {
		if (result.status==1) {//成功
			return dialog.success(result.message,result['data']['jump_url']);
		} else if(result.status==0){//失败
			return dialog.error(result.message,result['data']['jump_url']);
		}
	},'JSON');
});
